package com.ruoyi.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.user.domain.TbTenant;
import com.ruoyi.user.service.ITbTenantService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 租客管理Controller
 * 
 * @author ruoyi
 * @date 2024-10-08
 */
@RestController
@RequestMapping("/user/tenant")
public class TbTenantController extends BaseController
{
    @Autowired
    private ITbTenantService tbTenantService;

    /**
     * 查询租客管理列表
     */
    @PreAuthorize("@ss.hasPermi('user:tenant:list')")
    @GetMapping("/list")
    public TableDataInfo list(TbTenant tbTenant)
    {
        startPage();
        List<TbTenant> list = tbTenantService.selectTbTenantList(tbTenant);
        return getDataTable(list);
    }

    /**
     * 导出租客管理列表
     */
    @PreAuthorize("@ss.hasPermi('user:tenant:export')")
    @Log(title = "租客管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TbTenant tbTenant)
    {
        List<TbTenant> list = tbTenantService.selectTbTenantList(tbTenant);
        ExcelUtil<TbTenant> util = new ExcelUtil<TbTenant>(TbTenant.class);
        util.exportExcel(response, list, "租客管理数据");
    }

    /**
     * 获取租客管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('user:tenant:query')")
    @GetMapping(value = "/{tenantId}")
    public AjaxResult getInfo(@PathVariable("tenantId") Long tenantId)
    {
        return success(tbTenantService.selectTbTenantByTenantId(tenantId));
    }

    /**
     * 新增租客管理
     */
    @PreAuthorize("@ss.hasPermi('user:tenant:add')")
    @Log(title = "租客管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbTenant tbTenant)
    {
        return toAjax(tbTenantService.insertTbTenant(tbTenant));
    }

    /**
     * 修改租客管理
     */
    @PreAuthorize("@ss.hasPermi('user:tenant:edit')")
    @Log(title = "租客管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbTenant tbTenant)
    {
        return toAjax(tbTenantService.updateTbTenant(tbTenant));
    }

    /**
     * 删除租客管理
     */
    @PreAuthorize("@ss.hasPermi('user:tenant:remove')")
    @Log(title = "租客管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{tenantIds}")
    public AjaxResult remove(@PathVariable Long[] tenantIds)
    {
        return toAjax(tbTenantService.deleteTbTenantByTenantIds(tenantIds));
    }
}
